package com.marktotop.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.marktotop.entity.system.Log;
import com.marktotop.mapper.LogMapper;
import com.marktotop.response.ResultBean;
import com.marktotop.response.ResultCode;
import com.marktotop.service.ILogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.marktotop.vo.system.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 操作日志表 服务实现类
 * </p>
 *
 * @author MarkToTop
 * @since 2021-07-12
 */
@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, Log> implements ILogService {

    @Autowired
    private LogMapper logMapper;

    /**
     * 保存日志
     *
     * @param log
     */
    @Override
    public void saveLog(Log log) {
        logMapper.insert(log);
    }

    /**
     * 分页展示日志列表
     *
     * @param pageNum
     * @param pageSize
     * @param log
     * @return
     */
    @Override
    public ResultBean findLogList(Integer pageNum, Integer pageSize, Log log) {
        // 开启分页
        Page<Log> page = new Page<>(pageNum,pageSize);
        IPage<Log> logsByPage = logMapper.getLogsByPage(page,log);
        if (logsByPage.getRecords().isEmpty()){
            return ResultBean.result(ResultCode.NON_RESULT);
        }
        return ResultBean.ok().message("获取操作日志信息成功！")
                .data("total",logsByPage.getTotal())
                .data("logList",logsByPage.getRecords());
    }
}
